package com.att.service.impl;

import com.att.bean.UserOfRunDeilBean;
import com.att.dao.UserOfRunDeilDaoMapper;
import com.att.service.UserOfRunDeilService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

@Service("userOfRunDeilService")
public class UserOfRunDeilServiceImpl implements UserOfRunDeilService {

    @Resource
    private UserOfRunDeilDaoMapper userOfRunDeilDaoMapper;

    @Override
    public boolean insert(UserOfRunDeilBean bean) throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        List list = new ArrayList();
        String[] startTimeStr = bean.getStartTimeStr().split(",");
        for (int i = 0;i < startTimeStr.length;i++){
            UserOfRunDeilBean userOfRunDeilBean = new UserOfRunDeilBean();
            userOfRunDeilBean.setNumRunId(bean.getNumRunId());
            userOfRunDeilBean.setStartTime(format.parse(startTimeStr[i]));
            userOfRunDeilBean.setEndTime(format.parse(startTimeStr[i]));
            userOfRunDeilBean.setUserId(bean.getUserId());
            userOfRunDeilBean.setSchClassId(bean.getSchClassId());
//            userOfRunDeilBean.setDeilType(bean.getDeilType());
//            userOfRunDeilBean.setSchClassId(bean.getSchClassId());
//            userOfRunDeilBean.setAddWorkTime(bean.getAddWorkTime());
//            userOfRunDeilBean.setIsAddWork(bean.getIsAddWork());
            list.add(userOfRunDeilBean);
        }
        return userOfRunDeilDaoMapper.insert(list);
    }

    @Override
    public boolean delete(UserOfRunDeilBean bean) {
        return userOfRunDeilDaoMapper.delete(bean);
    }

    @Override
    public List<UserOfRunDeilBean> findUserOfRunDeilBean(UserOfRunDeilBean bean) {
        return userOfRunDeilDaoMapper.findUserOfRunDeilBean(bean);
    }

    /**
     * 删除时间班次时间段的时候删除排班的信息
     * @param week  删除周几的
     * @param numRunId
     * @return
     */
    public boolean deleteByWeek(String week, Integer numRunId){
        return userOfRunDeilDaoMapper.deleteByWeek( week, numRunId);
    }
    /**
     * 删除时间班次时间段的时候删除排班的信息
     * @param day
     * @param numRunId
     * @return
     */
    public boolean deleteByDay(String day,Integer numRunId){
        return userOfRunDeilDaoMapper.deleteByDay( day, numRunId);
    }
}
